var http = require('../../utils/http.js');
var config = require('../../utils/config.js');
Page({
    data: {
        records: [],
        recordsSprm: [],
        recordsGdbb: [],
        recordscs: [],
        sts: null,
        swiperList: [],
        indicatorDots: true,
        vertical: false,
        autoplay: true,
        interval: 2000,
        duration: 500
    },
    onLoad: function () {
        // 调用每日上新
        http.request({
            url: "/prod/prodListByTagId",
            method: "get",
            data: {
                tagId: 1,
                size: 6
            },
            callBack: res => {
                this.setData({
                    records: res.records
                })

                // console.log(this.records, "111");
            }
        });
        // 调用商城热销
        http.request({
            url: "/prod/prodListByTagId",
            method: "get",
            data: {
                tagId: 2,
                size: 6
            },
            callBack: res => {
                this.setData({
                    recordsSprm: res.records
                })
                // console.log(this.records, "111");
            }
        });
        // 调用更多宝贝
        http.request({
            url: "/prod/prodListByTagId",
            method: "get",
            data: {
                tagId: 3,
                size: 6
            },
            callBack: res => {
                this.setData({
                    recordsGdbb: res.records
                })
                // console.log(this.records, "111");
            }
        });
        // 调用测试
        http.request({
            url: "/prod/prodListByTagId",
            method: "get",
            data: {
                tagId: 7,
                size: 6
            },
            callBack: res => {
                this.setData({
                    recordscs: res.records
                })

                // console.log(this.records, "111");
            }
        });
        // 调用轮播图
        http.request({
            url: "/indexImgs",
            method: "get",
            data: {},
            callBack: res => {
                this.setData({
                    swiperList: res
                })
                // console.log(res, "232431");
            }
        })
    },
    // 搜索
    handleSearch() {
        wx.navigateTo({
            url: `/pages/search-page/search-page`
        })
    },
    // 轮播图跳转
    handBanner(e) {
        console.log(e.currentTarget.dataset.item.relation);
        if (e.currentTarget.dataset.item.relation) {
            wx.navigateTo({
                url: `/pages/prod/prod?prodid=${e.currentTarget.dataset.item.relation}`
            })
        }
    },
    // 新品推荐
    handleXptj() {
        const sts = 1
        wx.navigateTo({
            url: `/pages/prod-classify/prod-classify?sts=${sts}`
        })
        console.log(sts);
    },
    // 限时特惠
    handleXsth() {
        const sts = 1
        wx.navigateTo({
            url: `/pages/prod-classify/prod-classify?sts=${sts}`
        })
        console.log(sts);

    },
    // 每日疯抢
    handleMrfq() {
        const sts = 3
        wx.navigateTo({
            url: `/pages/prod-classify/prod-classify?sts=${sts}`
        })
        console.log(sts);

    },
    // 每日上新，商城热销···
    handBan(e) {
        // console.log(e.currentTarget.dataset.item);
        if (e.currentTarget.dataset.item.prodId) {
            wx.navigateTo({
                url: `/pages/prod/prod?prodid=${e.currentTarget.dataset.item.prodId}`
            })
        }
    },
    // 刷新购物车
    handleNewGw() {
        http.getCartCount()
    },
    // 添加购物车
    handleAddGw(e) {
        http.request({
            url: "/prod/prodInfo",
            method: "get",
            data: {
                prodId: e.currentTarget.dataset.item.prodId
            },
            callBack: res => {
                console.log(res);
                http.request({
                    url: "/p/shopCart/changeItem",
                    method: "post",
                    data: {
                        basketId: 0,
                        count: 1,
                        prodId: res.prodId,
                        shopId: res.shopId,
                        skuId: res.skuList[0].skuId,
                    },
                    callBack: res => {
                        wx.showToast({
                            title: "加入购物车成功",
                            icon: "none"
                        })
                        this.handleNewGw()
                    }
                })
            }
        })
    },
})